'use strict';

var fs = require('fs');

fs.readFile('testjs/sample.txt','utf-8',function(err,data){
    if(err){
        console.log(err);
    }else{
        console.log(data);
        var buf = new Buffer(data,'utf-8');
        console.log(buf.length + ' bytes');
        console.log(buf);
    }
});

console.log('-------------------');

fs.readFile('testjs/sample.png','utf-8',function(err,data){
    if(err){
        console.log(err);
    }else{
        // console.log(data);
        console.log(data.length + ' bytes');
        // var text = data.toString('utf-8');
        // console.log(text);
    }
});
try {   
    var data = fs.readFileSync('testjs/sample.txt','utf-8');
    console.log(data); 
} catch (error) {
    console.log(error);
}